package com.zmzncs.lmtc.module.promotion.controller;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_fee_scale.MonthRuleFeeScale;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_fee_scale.MonthRuleFeeScaleDTO;
import com.zmzncs.lmtc.module.promotion.pojo.month_rule_fee_scale.MonthRuleFeeScaleVO;
import com.zmzncs.lmtc.module.promotion.service.MonthRuleFeeScaleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-08-12
 */
@Api(tags = "月租规则的收费标准")
@RestController
@RequestMapping("/promotion/month-rule-paytype")
public class MonthRulePaytypeController {

    @Autowired
    MonthRuleFeeScaleService monthRuleFeeScaleService;

    @ApiOperation(value = "根据停车场id查询支付规则")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType = "query", name = "parkId", value = "停车场id", required = true),
    })
    @GetMapping(value = "getMonthRulePaytypeByParkId")
    public Rest<List<MonthRuleFeeScaleVO>> getMonthRulePaytypeByParkId(String parkId) {
        List<MonthRuleFeeScaleDTO> monthRuleFeeScaleDTOS = monthRuleFeeScaleService.getMonthRuleFeeScaleByParkId(parkId);
        List<MonthRuleFeeScaleVO> monthRuleFeeScaleVOS = JsonUtil.listTransform(monthRuleFeeScaleDTOS, MonthRuleFeeScaleVO.class);
        //  该停车场还没有开启VIP服务
        if (monthRuleFeeScaleVOS.size() == 0) {
            return RestUtil.warning("该停车场还没有开启VIP服务");
        } else {
            return RestUtil.success(monthRuleFeeScaleVOS);
        }
    }

//    @ApiOperation(value = "设置所有咪网月租手续费金额")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
//            @ApiImplicitParam(paramType = "query", name = "serviceAddAmount", value = "咪网月租手续费金额", required = true),
//    })
//    @GetMapping(value = "updateAllMWMonthServiceAddAmount")
//    public Rest updateAllMWMonthServiceAddAmount(@NotNull Integer serviceAddAmount) {
//        monthRuleFeeScaleService.updateAllMWMonthServiceAddAmount(serviceAddAmount);
//        return RestUtil.success();
//    }

//    @ApiOperation(value = "修改咪网单个月租手续费金额")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
//            @ApiImplicitParam(paramType = "query", name = "monthRuleId", value = "月租规则ID", required = true),
//            @ApiImplicitParam(paramType = "query", name = "monthCount", value = "月份", required = true),
//            @ApiImplicitParam(paramType = "query", name = "serviceAddAmount", value = "咪网月租手续费金额", required = true),
//    })
//    @GetMapping(value = "updateMWMonthServiceAddAmount")
//    public Rest updateMWMonthServiceAddAmount(@NotNull Long monthRuleId, @NotNull Integer monthCount, @NotNull Integer serviceAddAmount) {
//
//        LambdaUpdateWrapper<MonthRuleFeeScale> updateWrapper = new LambdaUpdateWrapper<>();
//        updateWrapper.eq(MonthRuleFeeScale::getMonthRuleId, monthRuleId).eq(MonthRuleFeeScale::getMonthRentType, monthCount);
//        MonthRuleFeeScale feeScale = new MonthRuleFeeScale();
//        feeScale.setServiceAddAmount(new BigDecimal(serviceAddAmount));
//        monthRuleFeeScaleService.update(feeScale, updateWrapper);
//        return RestUtil.success();
//    }


}

